<?php
/******************************************************************************
    NuCMS Framework, for the quick deployment of applications developed in
    php.
    Copyright (C) 2009  Matthew General

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
 * 
 * @author mgeneral
 *
 */
class PDOInstance extends PDO
{
	/**
	 * 
	 * @param config file path
	 * @return unknown_type
	 */
    public function __construct($file = 'Config/config.ini')
    {
        if (!$settings = parse_ini_file($file, TRUE)) throw new Error('Unable to open ' . $file . '.');
        	$dsn=$settings['database']['driver'];
        	unset($settings['database']['driver']);
        	$username=$settings['database']['username'];
        	unset($settings['database']['username']);
        	$password=$settings['database']['password'];
        	unset($settings['database']['password']);
        	foreach($settings['database'] as $key => $val) {
        		$dsn .= $key."=".$val.";";
        	}
        	$dsn = substr($dsn,0,-1);
        try{
        	parent::__construct($dsn,$username,$password);
        }catch(PDOException $e) {
        	die('Connection failed: ' . $e->getMessage());
        }
    }
}
?>